home *** CD-ROM | disk | FTP | other *** search
- ******************************************************************
- * COPYRIGHT (C) 1986 by Donald Krantz and James Stanley
- * - Note: This is a real, live, actual, registered copyright,
- * and should be treated as such. This source code is from
- * the book "68000 Assembly Language", Krantz and Stanley,
- * Addison-Wesley Publishing Company, Reading, MA, 1986.
- *
- * Permission granted by the authors for non-commercial use
- * in programs released to the public domain, as long as this
- * copyright notice remains attached and visible.
- *
- *****************************************************************
- * GROUP 2 (Block) Commands
-
- xref _getkey,ask,case,chk_blk,cnt_nl,default,dirty
- xref p_buf,p_cnt,prompt,putfile,query,readfile,seek
- xref writefile
- xdef group_2
-
- #edit.h
- #cursor.h
- *****************************************************************
- * GROUP_2 - group 2 (block) commands
- group_2:
- move.l #k_cmd,a0 * load up prompt address
- bsr prompt * output prompt
- bsr _getkey * get switch key
- and.w #$001F,d0 * make u/l, l/c letters cntrl
- move.l #table2,a0 * load up case table address
- bra case * returns to caller of group_2
- k_cmd: dc.b 'Block Command: B C D P Q R S V W Y X',0
- dc.w 0
- *****************************************************************
- * TABLE2 - switch table for group 2 commands
- table2:
- dc.w 12 * number of case options
- dc.w $0B * ^K mark block end
- dc.l mark_end
- dc.w $02 * ^B mark block start
- dc.l mark_start
- dc.w $03 * ^C copy block to cursor
- dc.l copy
- dc.w $04 * ^D end edit and save
- dc.l end_save
- dc.w $13 * ^S save and resume
- dc.l save
- dc.w $19 * ^Y cut block
- dc.l delete
- dc.w $10 * ^P Paste block
- dc.l paste
- dc.w $11 * ^Q abandon file
- dc.l abandon
- dc.w $17 * ^W write block
- dc.l write
- dc.w $12 * ^R read file
- dc.l readfile
- dc.w $16 * ^V move block
- dc.l mblock
- dc.w $18 * ^X end edit and save
- dc.l end_save
- dc.l default * all other options
- *****************************************************************
- * MARK_END - marks the gap as the end of the block
- mark_end:
- move.l b_gap(a5),blk_end(a5)
- rts
- *****************************************************************
- * MARK_START - marks the gap as the beginning of the block
- mark_start:
- move.l b_gap(a5),blk_st(a5)
- rts
- *****************************************************************
- * MBLOCK - moves the marked block to the cursor
- mblock:
- bsr delete * cut block
- tst.w ed_err(a5) * check for errors
- bne sk0_mbl * exit on error
- bsr paste * insert block here
- sk0_mbl:
- rts
- *****************************************************************
- * COPY - copies the marked block to the cursor
- copy:
- bsr chk_blk * look for valid block
- tst.w ed_err(a5) * look for error code
- bne sk0_cpy * error jump out
- move.l b_gap(a5),-(a7) * save current cursor position
- move.l blk_end(a5),d0 * we want to have cursor at end
- bsr seek * move to end of block
- move.l blk_st(a5),a0 * load source address
- move.l #p_buf,a1 * load destination address
- move.l blk_end(a5),d0 * calculate number of bytes
- sub.l a0,d0 * d0 is number of bytes
- move.l d0,d1 * save number of bytes
- bra sk1_cpy * loop test before loop
- lp0_cpy:
- move.b (a0)+,(a1)+ * transfer bytes
- sk1_cpy:
- dbra d0,lp0_cpy * loop test
- move.l (a7)+,d0 * get old cursor position
- move.w d1,p_cnt * save byte count
- bsr seek * go back to old cursor position
- bsr paste * get stuff in
- sk0_cpy:
- rts
- *****************************************************************
- * DELETE - cuts marked block and puts into paste buffer
- delete:
- bsr chk_blk * look for valid block
- tst.w ed_err(a5) * look for error code
- bne sk0_del * error jump out
- move.l b_gap(a5),-(a7) * save current cursor position
- move.l blk_end(a5),d0 * we want to have cursor at end
- bsr seek * move to end of block
- move.l blk_st(a5),a0 * load source address
- move.l #p_buf,a1 * load destination address
- move.l blk_end(a5),d0 * calculate number of bytes
- sub.l a0,d0 * d0 is number of bytes
- move.l d0,d1 * save number of bytes
- bra sk1_del * loop test before loop
- lp0_del:
- move.b (a0)+,(a1)+ * transfer bytes
- sk1_del:
- dbra d0,lp0_del * loop test
- move.l blk_st(a5),b_gap(a5) ** erase block
- move.l (a7)+,d0 * get old cursor position
- cmp.l b_gap(a5),d0 * were we past cursor?
- blt sk2_del * yes.
- sub.l d1,d0 * adjust for missing bytes
- cmp.l b_gap(a5),d0 * were we in gap?
- bge sk2_del * no, we're ok still
- move.l b_gap(a5),d0 * fake it.
- sk2_del:
- move.w d1,p_cnt * save byte count
- bsr seek * go back to old cursor position
- bsr cnt_nl * adjust line count
- bsr dirty * mark file as modified
- sk0_del:
- rts
- *****************************************************************
- * PASTE - pulls whatever's in paste buffer into cursor gap
- paste:
- tst.w p_cnt * check if paste buffer used
- beq sk0_pas * jump if empty
- move.l e_gap(a5),d0 * check for room.
- sub.l b_gap(a5),d0 * calculate gap size
- cmp.w p_cnt,d0 * test againt paste buffer
- bcs sk2_pas * jump on error
- bsr dirty * mark file as modified
- move.l b_gap(a5),a0 * get load address
- move.l #p_buf,a1 * get source address
- move.w p_cnt,d0 * get byte count
- bra sk3_pas * loop test before move
- lp0_pas:
- move.b (a1)+,(a0)+ * transfer byte
- sk3_pas:
- dbra d0,lp0_pas * loop for all bytes in p_buf
- move.l a0,b_gap(a5) * save new gap start pointer
- bsr cnt_nl * reset line count
- bra sk1_pas
- sk2_pas:
- move.w #10,ed_err(a5) * load "block too large" code
- bra sk1_pas * jump out
- sk0_pas:
- move.w #11,ed_err(a5) * load "paste buffer empty" code
- sk1_pas:
- rts
- *****************************************************************
- * WRITE - writes a marked block to disk
- write:
- bsr chk_blk * check for valid blocks
- tst.w ed_err(a5) * look at return code
- bne sk0_wrt * error jump
- move.l b_gap(a5),-(a7) * save cursor position
- move.l blk_end(a5),d0 * setup for seek
- bsr seek * seek end of block
- move.l blk_st(a5),a1 * setup for file write
- move.l blk_end(a5),d1 * compute number of bytes to write
- sub.l blk_st(a5),d1 * D1 is number of bytes in block
- bsr writefile * go try to write file
- move.l (a7)+,d0 * now put cursor back
- bsr seek
- sk0_wrt:
- rts
- *****************************************************************
- * SAVE - Saves file and resumes editing
- save:
- move.l b_gap(a5),-(a7) * save current gap position
- bsr putfile * save out the file
- move.l (a7)+,d0 * setup for seek
- bsr seek * put cursor back
- rts
- *****************************************************************
- * ABANDON - abondon file being edited
- abandon:
- tst.w modify(a5) * check for changes
- bne sk0_abn * confirm if modified
- lp0_abn:
- clr.l d0 * mark as don't resume editing
- addq.l #4,a7 * pop top return address
- rts * returns to 'edit's caller
- sk0_abn:
- move.l #confirm,a0 * confirm prompt
- move.l #query,a1 * general purpose response area
- bsr ask * check with the human
- and.b #$5F,query * make uppercase
- cmp.b #'Y',query * test for 'Y' or 'y'
- beq lp0_abn * human says ok, so dump it.
- rts * failed abandon exit
- confirm:
- dc.b 'Abandon modified file? (Y/N) ',0
- dc.w 0
- *****************************************************************
- end_save:
- bsr putfile * write the file to disk
- tst.w d0 * check return code
- bne sk0_ener * jump if error
- clr.l d0 * mark as don't resume editing
- addq.l #4,a7 * pop top return address
- rts * returns to caller of EDIT
- sk0_ener:
- rts * and back to edit main loop
-
- end